import result from './result.json';
import { IPlank, Order } from '@/types';
import { sample } from 'lodash-es';

export const order = {
  orderName: 'mock order name',
  orderId: 'mock-order-id',
  orderNo: 'mock-order-no',
  receiptType: sample([0, 1]),
} as Order;

const mockPlanks = result.d.result as unknown as IPlank[];
const mockPlank = result.d.result.at(1) as unknown as IPlank;
const changeMockPlank = (mockPlank: IPlank) =>
  mockPlank?.grooves.forEach((groove) => {
    // @ts-expect-error
    groove.geometryType ??= 'SQUARE';
  });
mockPlanks.map(changeMockPlank);
// mockPlanks.push(...mockPlanks.map(plank => plank));

export const planks: IPlank[] = mockPlanks || [
  {
    ...mockPlank,
    // geometryType: 'SQUARE',
  },
];
// console.log({ mockPlanks: planks });

export async function getPlanks() {
  return planks;
}

export const bomApi = {
  async list() {
    const planks = await getPlanks();
    return [
      {
        id: '-1',
        name: 'mock data',
        date: 1658816645984,
        data: planks,
      },
    ];
  },
};
